package com.adopt.controller;

import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: zhouyue
 * @Date: 2023/09/10/16:45
 * @Description:
 */
public class FileLoad {


    public static String load(MultipartFile file) {
        String picName = UUID.randomUUID().toString();
        //获取上传文件得元素得名称
        String fileName = file.getOriginalFilename();

        String substring = fileName.substring(fileName.lastIndexOf("."));

        //File destinationFile = new File(destinationPath);
        //上传文件
        try {

            //file.transferTo(destinationFile);
            file.transferTo(new File("D:/sky/" + picName + substring));

        } catch (IOException e) {

            e.printStackTrace();

            //   return new Result(200,e.getMessage(),null);

        }
        // return destinationPath;
        String name = picName + substring;

        return name;
    }
}
